#include <iostream>
/*
 * @Author: 缄默
 * @Date: 2021-09-17 18:48:53
 * @LastEditors: 缄默
 * @LastEditTime: 2021-12-13 16:28:46
 */

using namespace std;

//product
//抽象产品A 将其理解为空调
class abstractProductA {
public:
    virtual ~abstractProductA() {}
    virtual void Operation() = 0;
};

//抽象产品B 将其理解为电视机

class abstractProductB {
public:
    virtual ~abstractProductB() {}
    virtual void Operation() = 0;
};

//1牌的空调
class ProductA1 : public abstractProductA {
public:
    void Operation() {
        cout << "productA1 operation" << endl;
    }
};

//1牌的电视机
class ProductB1 : public abstractProductB {
public:
    void Operation() {
        cout << "ProductB1 operation" << endl;
    }
};


//2牌的空调
class ProductA2 : public abstractProductA {
public:
    void Operation() {
        cout << "productA2 operation" << endl;
    }
};

//2牌的电视机
class ProductB2 : public abstractProductB {
public:
    void Operation() {
        cout << "ProductB2 operation" << endl;
    }
};

//factory
class abstractFactory {
public:
    virtual ~abstractFactory() {}
    virtual abstractProductA *createProductA() = 0;
    virtual abstractProductB *createProductB() = 0;
};

//具体工厂1 用来生产1牌的电视机和空调
class concreteFactory1 : public abstractFactory {
public:
    abstractProductA *createProductA() {
        return new ProductA1();
    }
    abstractProductB *createProductB() {
        return new ProductB1();
    }
};


//具体工厂2，用来生产2牌的电视机和空调
class concreteFactory2 : public abstractFactory {
public:
    abstractProductA *createProductA() {
        return new ProductA2();
    }
    abstractProductB *createProductB() {
        return new ProductB2();
    }
};
int main() {
    abstractFactory *factory1 = new concreteFactory1();
    abstractFactory *factory2 = new concreteFactory2();

    abstractProductA *productA1 = factory1->createProductA();
    abstractProductB *productB1 = factory1->createProductB();
    abstractProductA *productA2 = factory2->createProductA();
    abstractProductB *productB2 = factory2->createProductB();

    productA1->Operation();
    productB1->Operation();
    productA2->Operation();
    productB2->Operation();

    delete factory1;
    delete factory2;
    delete productA1;
    delete productA2;
    delete productB1;
    delete productB2;
    return 0;
}